package org.jsrml.core.supplier.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;
import org.jsrml.common.persistence.StringIdBaseEntity;
import org.jsrml.common.util.UUIDGenerator;
import org.jsrml.core.supplier.command.SaveSupplyBankCo;

@DynamicUpdate
@Entity
@Table(name = M.TABLE_PREFIX + "SUPPLY_BANK")
@SuppressWarnings("serial")
public class SupplyBank extends StringIdBaseEntity {
	
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "VENDOR_ID", foreignKey = @ForeignKey(name = "none"))
	private Vendor vendor;
	
	/**
	 * 开户银行
	 */
	@Column(name = "BANK", length = 64)
	private String bank;
	
	/**
	 * 银行账号
	 */
	@Column(name = "ACCOUNT", length = 64)
	private String account;
	
	/**
	 * 主要银行账户，0：是，1：不是
	 */
	@Column(name = "MAIN_ACCOUNT", length = 4)
	private Integer mainAccount;
	
	/**
	 * 	是否停用，0：启用，1：停用
	 */
	@Column(name = "IS_CLOSE", length = 4)
	private Integer isClose;
	/**
	 * 停用人
	 */
	@Column(name = "CLOSED_BY", length = 64)
	private String closedBy;
	/**
	 * 停用时间
	 */
	@Column(name = "CLOSED_DATE", columnDefinition=M.DATE_COLUMN)
	private Date closedDate;
	
	
	public void create(SaveSupplyBankCo command,Vendor vendor){
		setId(UUIDGenerator.getUUID());
		setVendor(vendor);
		setBank(command.getBank());
		setAccount(command.getAccount());
		setMainAccount(command.getMainAccount());
		setIsClose(0);
	}
	
	public void modify(SaveSupplyBankCo command,Vendor vendor){
		setVendor(vendor);
		setBank(command.getBank());
		setAccount(command.getAccount());
		setMainAccount(command.getMainAccount());
	}
	
	public void close(){
		setIsClose(1);
		setClosedBy(null);
		setClosedDate(new Date());
	}
	
	public Vendor getVendor() {
		return vendor;
	}
	public void setVendor(Vendor vendor) {
		this.vendor = vendor;
	}
	public String getBank() {
		return bank;
	}
	public void setBank(String bank) {
		this.bank = bank;
	}
	public String getAccount() {
		return account;
	}
	public void setAccount(String account) {
		this.account = account;
	}
	public Integer getMainAccount() {
		return mainAccount;
	}
	public void setMainAccount(Integer mainAccount) {
		this.mainAccount = mainAccount;
	}
	public Integer getIsClose() {
		return isClose;
	}
	public void setIsClose(Integer isClose) {
		this.isClose = isClose;
	}
	public String getClosedBy() {
		return closedBy;
	}
	public void setClosedBy(String closedBy) {
		this.closedBy = closedBy;
	}
	public Date getClosedDate() {
		return closedDate;
	}
	public void setClosedDate(Date closedDate) {
		this.closedDate = closedDate;
	}
}
